<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
    <style>
        .bw{
            width: 550px;
            margin: 100px auto;
        }

        .msg{
            display:inline-block;
            font-size: 15px;
            color: darkolivegreen;
            background: url(images/mess.png) no-repeat left center;
            padding-left: 20px;
        }
        /* 密码不满足条件 */
        .bw1{
            color: red;
            background-image: url(images/wrong.png)
        }
        
        /* 密码满足条件 */
        .bw2{
            color: green;
            background-image: url(images/right.png)
        }
        
    </style>
</head>
<body>
    <div class="bw">
        <input type="password" class="passwd">
        <p class="msg">请输入6~16位</p>
    </div>

    <script>
        //获取input
        const inputObj1 = document.querySelector("input")
        const pObj1 = document.querySelector("p")

        //给inputObj1绑定事件
        /* 
            需求：只需要在鼠标离开密码框的时候出发判断就可以
         */
         inputObj1.onblur = function(){
            //  console.log(this.value)
            //  console.log(this.value.length)
            if(this.value.length<6||this.value.length>16){
                //不满足条件
                pObj1.className=' msg bw1'
                pObj1.innerText = '请输的密码不满足格式要求'
            }else{
                //满足条件
                pObj1.className = "msg bw2"
                pObj1.innerText = "输入真确"
            }
         }

    </script>
</body>
</html>